package com.nehc.nettyserver.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Data;

import java.util.Map;

/**
 * Netty服务器配置属性
 * 
 * @author nehc
 * @date 2023-04-02
 */
@Data
@Component
@ConfigurationProperties(prefix = "netty.server")
public class NettyServerProperties {

    /**
     * 端口号
     */
    private int port = 8081;

    /**
     * Boss线程数
     */
    private int bossThreads = 1;

    /**
     * Worker线程数
     */
    private int workerThreads = 4;

    /**
     * 通道选项配置
     */
    private Map<String, Object> channelOptions;

    /**
     * WebSocket配置
     */
    private WebSocketProperties websocket = new WebSocketProperties();

    /**
     * 心跳配置
     */
    private HeartbeatProperties heartbeat = new HeartbeatProperties();

    /**
     * 消息配置
     */
    private MessageProperties message = new MessageProperties();

    /**
     * WebSocket配置属性
     */
    @Data
    public static class WebSocketProperties {
        /**
         * WebSocket路径
         */
        private String path = "/ws";

        /**
         * 最大帧大小(字节)
         */
        private int maxFrameSize = 65536;
    }

    /**
     * 心跳配置属性
     */
    @Data
    public static class HeartbeatProperties {
        /**
         * 心跳间隔(秒)
         */
        private int interval = 30;

        /**
         * 心跳超时时间(秒)
         */
        private int timeout = 60;
    }

    /**
     * 消息配置属性
     */
    @Data
    public static class MessageProperties {
        /**
         * 最大消息大小(字节)
         */
        private int maxSize = 65536;

        /**
         * 是否压缩消息
         */
        private boolean compression = true;
    }
} 